package com.qfmy.web.entity.MysqlDao;


import lombok.SneakyThrows;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.DriverManager;
/**
 * @author: 廖志伟
 * @date: 2024-11-28
 * 操作表
 */
@SuppressWarnings("all")
public class MysqlConfigDao {
   //定义一个日志对象
   private static final Logger logger = LoggerFactory.getLogger(MysqlConfigDao.class);
   private static String driver = "com.mysql.cj.jdbc.Driver";
   private static String url = "jdbc:mysql://localhost:3307/EasyJob?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC";
   private static String username = "root";
   private static String password = "1234";
   private static Connection connection;

   /**
    * 获取数据库连接
    * @return
    */
   @SneakyThrows
   public static Connection getConnection() {
      //加载驱动
      Class.forName(driver);
      //获取连接
      connection = DriverManager.getConnection(url,username,password);
      //返回连接对象
      return connection;
   }

   /**
    * 关闭数据库连接
    */
   @SneakyThrows
   public static void close()
   {
      connection.close();
   }
}
